package com.wxxymaker.utils;

import jxl.format.Alignment;
import jxl.format.Colour;
import jxl.format.VerticalAlignment;
import jxl.write.*;

/**
 * @Author: Soft
 * @Date: 2018/5/15 0:06
 * @Desc: Excel表格字体样式
 */
public class WorkBookUtil {
    public static WritableCell getDefaultCell(int c, int r, String content) throws WriteException {
        return new Label(c, r, content, WorkBookUtil.getDefaultStyle());
    }

    public static WritableCellFormat getTitleStyle() throws WriteException {
        WritableCellFormat style = new WritableCellFormat();  // 单元格样式
        WritableFont font  = new WritableFont(WritableFont.createFont("宋体"));  // 字体
        font.setColour(Colour.BLACK);  // 设置字体颜色
        style.setAlignment(Alignment.CENTRE); // 设置单元格水平居中
        style.setVerticalAlignment(VerticalAlignment.CENTRE); // 设置单元格垂直居中
        style.setFont(font);  // 设置字体

        return style;
    }

    public static WritableCellFormat getHeaderStyle() throws WriteException {
        WritableCellFormat style = new WritableCellFormat();  // 单元格样式
        WritableFont font  = new WritableFont(WritableFont.createFont("宋体"),
                WritableFont.DEFAULT_POINT_SIZE, WritableFont.BOLD);  // 字体
        font.setColour(Colour.WHITE);  // 设置字体颜色
        style.setAlignment(Alignment.CENTRE); // 设置单元格水平居中
        style.setVerticalAlignment(VerticalAlignment.CENTRE); // 设置单元格垂直居中
        style.setBackground(Colour.BLUE_GREY);  // 设置单元格背景色
        style.setFont(font);  // 设置字体

        return style;
    }

    public static WritableCellFormat getDefaultStyle() throws WriteException {
        WritableCellFormat style = new WritableCellFormat();  // 单元格样式
        style.setAlignment(Alignment.CENTRE); // 设置单元格水平居中
        style.setVerticalAlignment(VerticalAlignment.CENTRE); // 设置单元格垂直居中

        return style;
    }

    public static WritableCellFormat getRedFont() throws WriteException {
        WritableFont font  = new WritableFont(WritableFont.createFont("宋体"));  // 字体
        font.setColour(Colour.RED);  // 设置字体颜色

        WritableCellFormat defaultStyle = WorkBookUtil.getDefaultStyle();
        defaultStyle.setFont(font);
        return defaultStyle;
    }

    public static WritableCellFormat getGreenFont() throws WriteException {
        WritableFont font  = new WritableFont(WritableFont.createFont("宋体"));  // 字体
        font.setColour(Colour.GREEN);  // 设置字体颜色

        WritableCellFormat defaultStyle = WorkBookUtil.getDefaultStyle();
        defaultStyle.setFont(font);
        return defaultStyle;
    }

    public static WritableCellFormat getBlueFont() throws WriteException {
        WritableFont font  = new WritableFont(WritableFont.createFont("宋体"));  // 字体
        font.setColour(Colour.BLUE);  // 设置字体颜色

        WritableCellFormat defaultStyle = WorkBookUtil.getDefaultStyle();
        defaultStyle.setFont(font);
        return defaultStyle;
    }
}
